package com.zy.yun.base.common;

import java.io.Serializable;

/**
 * Rest返回结果
 * @author Rlax
 *
 */
public class RestResult<T> implements Serializable {

    @Override
    public String toString() {
        return "RestResult{" +
                "code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                ", result=" + result +
                '}';
    }

    /**
	 * 
	 */
	private static final long serialVersionUID = 129776277253970021L;
	private  String code;
    private  String msg;

    private T result;

    public RestResult() {

    }

    public RestResult(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public RestResult(String code, String msg, T result) {
        this.code = code;
        this.msg = msg;
        this.result = result;
    }

    public static RestResult    buildSuccess() {
        RestResult restResult = new RestResult();
        restResult.success();
        return restResult;
    }

    public static RestResult buildSuccess(Object t) {
        RestResult restResult = buildSuccess();
        restResult.setResult(t);
        return restResult;
    }

    public static RestResult buildError() {
        RestResult restResult = new RestResult();
        restResult.error();
        return restResult;
    }

    public static RestResult buildError(String msg) {
        RestResult restResult = new RestResult();
        restResult.error(msg);
        return restResult;
    }

    public RestResult success() {
        this.code = ResultCode.SUCCESS;
        this.msg = "操作成功";
        return this;
    }

    public RestResult success(T t) {
        success();
        this.result = t;
        return this;
    }

    public RestResult error() {
        this.code = ResultCode.ERROR;
        this.msg = "操作失败";
        return this;
    }

    public RestResult error(String msg) {
        this.code = ResultCode.ERROR;
        this.msg = msg;
        return this;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

  
    
    public T getResult() {
		return result;
	}

	public void setResult(T result) {
		this.result = result;
	}

	public RestResult abnormal() {
        this.code = ResultCode.ABNORMAL_ERROR;
        this.msg = "异常操作";
        return this;
    }
    
    public static RestResult buildAbnormal(Object t) {
        RestResult restResult = buildAbnormal();
        restResult.setResult(t);
        return restResult;
    }
    
    public static RestResult buildAbnormal() {
        RestResult restResult = new RestResult();
        restResult.abnormal();
        return restResult;
    }
    
    public RestResult parameter() {
        this.code = ResultCode.PARAMETER_ERROR;
        this.msg = "参数为空";
        return this;
    }
    
    public static RestResult buildParameter(Object t) {
        RestResult restResult = buildParameter();
        restResult.setResult(t);
        return restResult;
    }
    
    public static RestResult buildParameter() {
        RestResult restResult = new RestResult();
        restResult.parameter();
        return restResult;
    }
    public RestResult perAudit() {
        this.code = ResultCode.PERAUDIT_CODE;
        this.msg = "审核中";
        return this;
    }
    
    public static RestResult buildPerAudit(Object t) {
        RestResult restResult = buildPerAudit();
        restResult.setResult(t);
        return restResult;
    }
    
    public static RestResult buildPerAudit() {
        RestResult restResult = new RestResult();
        restResult.perAudit();
        return restResult;
    }
    
    public RestResult perPassed() {
        this.code = ResultCode.PERPASSED_CODE;
        this.msg = "认证通过";
        return this;
    }
    
    public static RestResult buildPerPassed(Object t) {
        RestResult restResult = buildPerPassed();
        restResult.setResult(t);
        return restResult;
    }
    
    public static RestResult buildPerPassed() {
        RestResult restResult = new RestResult();
        restResult.perPassed();
        return restResult;
    }
    public RestResult perNoPassed() {
        this.code = ResultCode.PERNOPASSED_CODE;
        this.msg = "认证失败";
        return this;
    }
    
    public static RestResult buildPerNoPassed(Object t) {
        RestResult restResult = buildPerNoPassed();
        restResult.setResult(t);
        return restResult;
    }
    
    public static RestResult buildPerNoPassed() {
        RestResult restResult = new RestResult();
        restResult.perNoPassed();
        return restResult;
    }
    
    public RestResult comAudit() {
        this.code = ResultCode.COMAUDIT_CODE;
        this.msg = "审核中";
        return this;
    }
    
    public static RestResult buildComAudit(Object t) {
        RestResult restResult = buildComAudit();
        restResult.setResult(t);
        return restResult;
    }
    
    public static RestResult buildComAudit() {
        RestResult restResult = new RestResult();
        restResult.comAudit();
        return restResult;
    }
    
    public RestResult comPassed() {
        this.code = ResultCode.COMPASSED_CODE;
        this.msg = "认证通过";
        return this;
    }
    
    public static RestResult buildComPassed(Object t) {
        RestResult restResult = buildComPassed();
        restResult.setResult(t);
        return restResult;
    }
    
    public static RestResult buildComPassed() {
        RestResult restResult = new RestResult();
        restResult.comPassed();
        return restResult;
    }
    public RestResult comNoPassed() {
        this.code = ResultCode.COMNOPASSED_CODE;
        this.msg = "认证失败";
        return this;
    }
    
    public static RestResult buildComNoPassed(Object t) {
        RestResult restResult = buildComNoPassed();
        restResult.setResult(t);
        return restResult;
    }
    
    public static RestResult buildComNoPassed() {
        RestResult restResult = new RestResult();
        restResult.comNoPassed();
        return restResult;
    }
}
